this._dashSpacer = new DashSpacer();
this._dashSpacer.setDashActor(this._dashSlider);
- this._thumbnailsBox = new WorkspaceThumbnail.ThumbnailsBox();
+ let workspaceManager = global.workspace_manager;
+ let activeWorkspaceIndex = workspaceManager.get_active_workspace_index();
+
+ this._workspaceAdjustment = new St.Adjustment({
+ value: activeWorkspaceIndex,
+ lower: 0,
+ page_increment: 1,
+ page_size: 1,
+ step_increment: 0,
+ upper: workspaceManager.n_workspaces,
+ });
+
+ this._nWorkspacesNotifyId =
+ workspaceManager.connect('notify::n-workspaces',
+ this._updateAdjustment.bind(this));
+
+ this._thumbnailsBox =
+ new WorkspaceThumbnail.ThumbnailsBox(this._workspaceAdjustment);
this._thumbnailsSlider = new ThumbnailsSlider(this._thumbnailsBox);
this.viewSelector = new ViewSelector.ViewSelector(searchEntry,
- this.dash.showAppsButton);
+ this._workspaceAdjustment, this.dash.showAppsButton);
this.viewSelector.connect('page-changed', this._setVisibility.bind(this));
this.viewSelector.connect('page-empty', this._onPageEmpty.bind(this));
layout.connect('allocation-changed', this._updateWorkspacesGeometry.bind(this));
Main.overview.connect('showing', this._updateSpacerVisibility.bind(this));
+
+ this.connect('destroy', this._onDestroy.bind(this));
+ }
+
+ _onDestroy() {
+ global.workspace_manager.disconnect(this._nWorkspacesNotifyId);
+ }
+
+ _updateAdjustment() {
+ let workspaceManager = global.workspace_manager;
+ let newNumWorkspaces = workspaceManager.n_workspaces;
+ let activeIndex = workspaceManager.get_active_workspace_index();
+
+ this._workspaceAdjustment.upper = newNumWorkspaces;
+
+ // A workspace might have been inserted or removed before the active
+ // one, causing the adjustment to go out of sync, so update the value
+ this._workspaceAdjustment.value = activeIndex;
}
_updateWorkspacesGeometry() {
'page-empty': {},
},
}, class ViewSelector extends Shell.Stack {
- _init(searchEntry, showAppsButton) {
+ _init(searchEntry, workspaceAdjustment, showAppsButton) {
super._init({
name: 'viewSelector',
x_expand: true,
this._iconClickedId = 0;
this._capturedEventId = 0;
- this._workspacesDisplay = new WorkspacesView.WorkspacesDisplay();
+ this._workspacesDisplay =
+ new WorkspacesView.WorkspacesDisplay(workspaceAdjustment);
this._workspacesPage = this._addPage(this._workspacesDisplay,
_("Windows"), 'focus-windows-symbolic');
const DND = imports.ui.dnd;
const Main = imports.ui.main;
const Workspace = imports.ui.workspace;
-const WorkspacesView = imports.ui.workspacesView;
// The maximum size of a thumbnail is 1/10 the width and height of the screen
let MAX_THUMBNAIL_SCALE = 1 / 10.;
0, Infinity, 0),
},
}, class ThumbnailsBox extends St.Widget {
- _init() {
+ _init(scrollAdjustment) {
super._init({ reactive: true,
style_class: 'workspace-thumbnails',
request_mode: Clutter.RequestMode.WIDTH_FOR_HEIGHT });
this._syncStackingId = 0;
this._workareasChangedId = 0;
- let workspaceManager = global.workspace_manager;
- let activeWorkspaceIndex = workspaceManager.get_active_workspace_index();
- this._scrollAdjustment = new St.Adjustment({
- value: activeWorkspaceIndex,
- lower: 0,
- page_increment: 1,
- page_size: 1,
- step_increment: 0,
- upper: workspaceManager.n_workspaces,
- });
+ this._scrollAdjustment = scrollAdjustment;
+
+ this._scrollAdjustment.connect('notify::value', adj => {
+ let workspaceManager = global.workspace_manager;
+ let activeIndex = workspaceManager.get_active_workspace_index();
+
+ this._animatingIndicator = adj.value !== activeIndex;
+
+ if (!this._animatingIndicator)
+ this._queueUpdateStates();
- this._scrollAdjustment.connect('notify::value', () => {
this.queue_relayout();
});
}
_createThumbnails() {
let workspaceManager = global.workspace_manager;
- this._switchWorkspaceNotifyId =
- global.window_manager.connect('switch-workspace',
- this._activeWorkspaceChanged.bind(this));
this._nWorkspacesNotifyId =
workspaceManager.connect('notify::n-workspaces',
this._workspacesChanged.bind(this));
if (this._thumbnails.length == 0)
return;
- if (this._switchWorkspaceNotifyId > 0) {
- global.window_manager.disconnect(this._switchWorkspaceNotifyId);
- this._switchWorkspaceNotifyId = 0;
- }
if (this._nWorkspacesNotifyId > 0) {
let workspaceManager = global.workspace_manager;
workspaceManager.disconnect(this._nWorkspacesNotifyId);
let oldNumWorkspaces = validThumbnails.length;
let newNumWorkspaces = workspaceManager.n_workspaces;
- this._scrollAdjustment.upper = newNumWorkspaces;
-
if (newNumWorkspaces > oldNumWorkspaces) {
this.addThumbnails(oldNumWorkspaces, newNumWorkspaces - oldNumWorkspaces);
} else {
childBox.y2 = indicatorY2 + indicatorBottomFullBorder;
this._indicator.allocate(childBox, flags);
}
-
- _activeWorkspaceChanged(_wm, from, to, _direction) {
- this._scrollAdjustment.value = from;
- this._animatingIndicator = true;
- this._scrollAdjustment.ease(to, {
- progress_mode: Clutter.AnimationMode.EASE_OUT_QUAD,
- duration: WorkspacesView.WORKSPACE_SWITCH_TIME,
- onComplete: () => {
- this._animatingIndicator = false;
- this._queueUpdateStates();
- },
- });
- }
});
var WorkspacesDisplay = GObject.registerClass(
class WorkspacesDisplay extends St.Widget {
- _init() {
+ _init(scrollAdjustment) {
super._init({ clip_to_allocation: true });
this.connect('notify::allocation', this._updateWorkspacesActualGeometry.bind(this));
let workspaceManager = global.workspace_manager;
- let activeWorkspaceIndex = workspaceManager.get_active_workspace_index();
- this._scrollAdjustment = new St.Adjustment({
- value: activeWorkspaceIndex,
- lower: 0,
- page_increment: 1,
- page_size: 1,
- step_increment: 0,
- upper: workspaceManager.n_workspaces,
- });
-
- workspaceManager.bind_property('n-workspaces',
- this._scrollAdjustment, 'upper', GObject.BindingFlags.SYNC_CREATE);
+ this._scrollAdjustment = scrollAdjustment;
this._switchWorkspaceId =
global.window_manager.connect('switch-workspace',